package pers.lls.im.core.task;

import pers.lls.im.core.api.MessagePersistService;
import pers.lls.im.core.common.bean.ChatMessage;
import pers.lls.im.core.common.bean.TransType;

import java.util.concurrent.Callable;

/**
 * @author lihuan
 * @version V1.0 创建时间：2019/8/02
 * Copyright 2019 by landray & STIC
 */
public class DataCallable implements Callable<Boolean> {


    private final MessagePersistService messagePersistService;

    /**
     * 业务消息
     */
    private ChatMessage chatMessage;

    DataCallable(MessagePersistService messagePersistService, ChatMessage chatMessage) {
        this.messagePersistService = messagePersistService;
        this.chatMessage = chatMessage;
    }

    @Override
    public Boolean call() {
        if (chatMessage.getType().equals(TransType.SEND_TO_ONE.getCode())){
            messagePersistService.messagePersist(chatMessage);
        }else {
            messagePersistService.groupMessagePersist(chatMessage);
        }

        return true;
    }
}
